#ifndef WORKPIECEE452_H
#define WORKPIECEE452_H

#include <QDebug>


#include <string.h>
#include <thread>
#include <mutex>
#include <map>
#include <condition_variable>
#include "../MeasureWorkpiece.h"

#include "MeasurE452AlgBase.h"
#include "MeasurE452AlgBackD1ToD8Circle.h"
#include "MeasurE452AlgBackDatum.h"
#include "MeasurE452AlgBackL1ToL8Circle.h"
#include "MeasurE452AlgBackR1ToR4Circle.h"
#include "MeasurE452AlgBackS1S2S4S5HighS3Circle.h"
#include "MeasurE452AlgBackSs1Ss2Circle.h"
#include "MeasurE452AlgFrontSe1ToSe9Edge.h"
#include "MeasurE452AlgHighSs3ToSs7Circle.h"
#include "MeasurE452EdgeDetect.h"
#include "MeasurE452ParaMeterClass.h"


#define         MAX_THREAD_NUM_E452             8

class WorkpieceE452 : public MeasureWorkpiece
{
public:
    WorkpieceE452();
    ~WorkpieceE452();

    bool SetTemplatePath(const std::string &path);
    bool SetStandardVal(const std::map<std::string, MeasureItemStandardVal> &standardValMap);
    void CacheData(const cv::Mat &image         ,
                   const QPoint &datumOffset    ,
                   int workpieceId              ,
                   int pictureId                ,
                   int channelId                ,
                   int fixtureId);

    void ProcessData();
    bool GetDatumPixelDistance(const QImage &img,
                               int fixtureId,
                               QMap<QString, float> &pixelDistance);
    void InitThread();
    void ExitThread();

private:
    void CorrectThreeD(std::map<std::string, float> &measRes, int fixtureId);
    float CalPosition(std::map<std::string, float> &measRes,
                      std::string strX, std::string strY);

private:
    QMap<int, WorkpieceInfo>                    m_workpieceMap;
    std::mutex                                  m_ioMutex;
    std::vector<std::thread>                    m_threadPool;
    bool                                        m_initThreadFinished_;          // 线程初始化完成标志
    std::atomic<bool>                           m_isSetPathFlag      ;


public:
    WorkpieceBuff                               m_workpieceBuff;
    bool                                        m_threadStopFlag;               // 线程停止标志
//    bool                                        m_isDataCorrect;
    std::string                                 m_configPath;

};

#endif // WORKPIECEE452_H
